package com.jml.exchange.点对点;


import com.jml.utils.MQConnectionUtils;
import com.rabbitmq.client.AMQP.BasicProperties;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import java.io.IOException;

/**
 * @author:jml
 * @date: 2020/3/3 13:25
 * @description：
 */
public class Consumer {
	
	static final String QUEUE_NAME = "point-to-point";
	
	 public static void main(String[] args) throws Exception {
		 Connection connection = MQConnectionUtils.newConnection();
		 Channel channel = connection.createChannel();
		 DefaultConsumer defaultConsumer = new DefaultConsumer(channel) {
			 @Override
			 public void handleDelivery(String consumerTag, Envelope envelope,
					 BasicProperties properties, byte[] body) throws IOException {
				 String msg = new String(body, "UTF-8");
				 System.out.println("消费者消费："+msg);
			 }
		 };
		 channel.basicConsume(QUEUE_NAME,true,defaultConsumer);
	 }
}
